package com.woniu.outpatient.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniu.outpatient.domain.Drugtype;
import com.woniu.outpatient.service.IDrugtypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 药品类型表Controller
 * 
 * @author wolf-six
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/drugtype")
public class DrugtypeController extends BaseController
{
    @Autowired
    private IDrugtypeService drugtypeService;

    /**
     * 查询药品类型表列表
     */
    @RequiresPermissions("outpatient:drugtype:list")
    @GetMapping("/list")
    public TableDataInfo list(Drugtype drugtype)
    {
        startPage();
        List<Drugtype> list = drugtypeService.selectDrugtypeList(drugtype);
        return getDataTable(list);
    }

    /**
     * 导出药品类型表列表
     */
    @RequiresPermissions("outpatient:drugtype:export")
    @Log(title = "药品类型表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drugtype drugtype)
    {
        List<Drugtype> list = drugtypeService.selectDrugtypeList(drugtype);
        ExcelUtil<Drugtype> util = new ExcelUtil<Drugtype>(Drugtype.class);
        util.exportExcel(response, list, "药品类型表数据");
    }

    /**
     * 获取药品类型表详细信息
     */
    @RequiresPermissions("outpatient:drugtype:query")
    @GetMapping(value = "/{drugtypeId}")
    public AjaxResult getInfo(@PathVariable("drugtypeId") Long drugtypeId)
    {
        return success(drugtypeService.selectDrugtypeByDrugtypeId(drugtypeId));
    }

    /**
     * 新增药品类型表
     */
    @RequiresPermissions("outpatient:drugtype:add")
    @Log(title = "药品类型表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drugtype drugtype)
    {
        return toAjax(drugtypeService.insertDrugtype(drugtype));
    }

    /**
     * 修改药品类型表
     */
    @RequiresPermissions("outpatient:drugtype:edit")
    @Log(title = "药品类型表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drugtype drugtype)
    {
        return toAjax(drugtypeService.updateDrugtype(drugtype));
    }

    /**
     * 删除药品类型表
     */
    @RequiresPermissions("outpatient:drugtype:remove")
    @Log(title = "药品类型表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drugtypeIds}")
    public AjaxResult remove(@PathVariable Long[] drugtypeIds)
    {
        return toAjax(drugtypeService.deleteDrugtypeByDrugtypeIds(drugtypeIds));
    }
}
